package Dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import Model.Type;
import utils.DBHelper;

public class TypeDao {
   Connection conn;
    String sql ;
    PreparedStatement ps;
    ResultSet rs;
    
    public TypeDao() {
    	conn = DBHelper.getConnection();
    }
    
    public ArrayList<Type> getAll(){
    	sql = "select * from tb_kind";
    	ArrayList<Type> list = new ArrayList<Type>();
    	try {
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery();
	    	
	    	while(rs.next()) {
	    		int type_id = rs.getInt("type_id");
	    		String typename = rs.getString("typename");
	    		Type type = new Type(type_id,typename);
	    		list.add(type);
	    	}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
    	return list;
    }
}
